package cn.tlb.ui.widget;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;

import cn.tlb.xutilsdownload.R;

public class SwipeRefreshActivity extends AppCompatActivity {
    SwipeRefreshLayout refreshLayout;
    TextView textView;
    private static final String TAG = SwipeRefreshActivity.class.getSimpleName();
    // You need to use a Theme.AppCompat theme (or descendant) with this activity
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        refreshLayout = (SwipeRefreshLayout) getLayoutInflater().inflate(R.layout.activity_swipe_refresh, null);
        setContentView(refreshLayout);
        textView = (TextView) findViewById(R.id.textView1);
        refreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);
        refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                refreshLayout.setRefreshing(true);
                Log.d("Swipe", "Refreshing Number");
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        refreshLayout.setRefreshing(false);
                        double f = Math.random();
                        textView.setText(String.valueOf(f));
                    }
                }, 3000);
            }
        });

    }
}
